<?php
namespace Yzadmin\Controller;
use Common\Controller\AdminBaseController;
/**
 * 后台单页控制器
 */
class PagesController extends AdminBaseController {
    /*单页管理首页*/
    public function index(){
        $lists=D('Category')->formatTree();
        $assign=array(
            'lists'=>$lists,
            'category'=>D('Category')->getAll()
            );
      $this->assign($assign);
        $this->display();
    }

    /*单页编辑页面*/
    public function edit(){
      if (IS_POST){
        $data = I('post.data');$id = intval(I('post.id'));
        if(empty($id)){$this->error('服务器正忙，请稍后再试！');}
        $result = D('Pages')->where(array('id'=>$id))->save($data);
        if(false !== $result){
          $this->success('数据操作成功！',U('Category/index'));exit;
        }else{
          $this->error('服务器正忙，请稍后再试！');
        }
      }
      $catid=I('get.id');if(empty($catid)){$this->error('非法操作!');}
      $info = D('Pages')->where(array('catid'=>$catid))->find();if(empty($info)){$this->error('信息不存在!');}
      $assign=array(
            'info'=>$info
            );
      $this->assign($assign);
      $this->display();
    }

}
